﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class SystemUpDownForm : System.Windows.Forms.Form
	{
		public SystemUpDownForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.usersetting = new HVACUserSetting();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.SetUserSetting();
			if (YJKMessageBox.Show("该操作将系统整体提升，包括末端设备等，是否继续？", MessageBoxButtons.YesNo) == DialogResult.Yes)
			{
				base.DialogResult = DialogResult.OK;
				return;
			}
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
			base.Close();
		}

		private void rbtnUpTo_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtnUpTo.Checked)
			{
				this.hytbUpTo.Enabled = true;
				this.hytbUpBy.Enabled = false;
				this.systemUpStyle = 0;
				return;
			}
			if (this.rbtnUpBy.Checked)
			{
				this.hytbUpTo.Enabled = false;
				this.hytbUpBy.Enabled = true;
				this.systemUpStyle = 1;
			}
		}

		private void SystemUpDownForm_Load(object sender, EventArgs e)
		{
			SystemUpDownSetPara systemUpDownPara = this.usersetting.GetSystemUpDownPara();
			this.hytbUpTo.Text = systemUpDownPara.UpTo.ToString();
			this.hytbUpBy.Text = systemUpDownPara.UpBy.ToString();
			if (systemUpDownPara.Style == 0)
			{
				this.rbtnUpTo.Checked = true;
				return;
			}
			this.rbtnUpBy.Checked = true;
		}

		private void SetUserSetting()
		{
			SystemUpDownSetPara systemUpDownSetPara = new SystemUpDownSetPara();
			systemUpDownSetPara.Style = this.systemUpStyle;
			systemUpDownSetPara.UpTo = double.Parse(this.hytbUpTo.Text.Trim());
			systemUpDownSetPara.UpBy = double.Parse(this.hytbUpBy.Text.Trim());
			if (this.systemUpStyle == 0)
			{
				this.dUpDown = systemUpDownSetPara.UpTo;
			}
			else
			{
				this.dUpDown = systemUpDownSetPara.UpBy;
			}
			this.usersetting.SetSystemUpDownPara(systemUpDownSetPara);
		}

		public int systemUpStyle;

		public double dUpDown;

		private HVACUserSetting usersetting;
	}
}
